/*
 *   This file is part of <open-parametrics>
 *   Copyright (c) 2006-2008 Miguel-Angel Sicilia
 *
 *   open-parametrics is free software: you can redistribute it and/or modify
 *   it under the terms of the Lesser GNU General Public License as
 *   published by the Free Software Foundation, either version 3 of
 *   the License, or (at your option) any later version.
 *
 *   open-parametrics is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with open-parametrics.  If not, see <http://www.gnu.org/licenses/>.
 */

package es.uah.cc.ie.parametrics.softeng;

import es.uah.cc.ie.parametrics.CostDriver;
import es.uah.cc.ie.parametrics.CostDriverValue;
import es.uah.cc.ie.parametrics.CostEstimatingRelationship;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author Miguel-Angel Sicilia
 */
public class SimpleExponentialSoftwareCER extends CostEstimatingRelationship {

    private double _coef;
    private double _exp;
    private CostDriver _size;

    public SimpleExponentialSoftwareCER(String label,
                                            double coef, double exp,
                                            CostDriver size){
        super(label); _coef=coef; _exp=exp; _size = size;
    }
    
    /**
     * A harcoded exponential model for software effort estimation.
     * effort = a* size^b
     *
     * @param instance The concrete case for which the estimation is desired.
     * @return An estimation of effort in man-months.
     */
    @Override
    public double estimate(List<CostDriverValue> instance) {
        // Find the value for the cost driver size:
        CostDriverValue cdv = null;
        for (Iterator it = instance.iterator(); it.hasNext();){
            cdv = (CostDriverValue)it.next();
            if (cdv.isValueOf(_size))
               break;
        }
        if (cdv !=null){
            double size=cdv.getValue();
            return _coef* Math.pow(size, _exp);
        }else
            return Double.NaN;
    
    }

 }
